<!--
推荐type=3时，代理商的功能，BD没有
-->
<template>
    <div class="myhome">
        <div class="head">
            <img v-bind:src="avatar" slot="icon" class="avatar">
            <span class="name">{{name}}</span>
        </div>

        <wv-group>
            <wv-cell-swipe v-if="type==3" title="推荐" is-link to="/recommend"></wv-cell-swipe>
            <wv-cell-swipe title="个人资料" is-link to=""></wv-cell-swipe>
            <wv-cell title="当前版本">
                <span slot="ft">v1.0</span>
            </wv-cell>
            <wv-cell title="收货地址管理" v-if="type==3" is-link to="">
                <span slot="ft"></span>
            </wv-cell>
            <wv-cell title="设置洗涤套餐" v-if="type==3" is-link to="">
                <span slot="ft"></span>
            </wv-cell>
            <wv-cell title="钱包" v-if="type==3" is-link to="/moneybag">
                <span slot="ft"></span>
            </wv-cell>
            <wv-cell-swipe title="退出登录" is-link to=""></wv-cell-swipe>
        </wv-group>
        <tabbar :type="type"></tabbar>
    </div>
</template>

<script>
import info from '../info.js'
import tabbar from '../views/tabbar'
import { Dialog } from 'we-vue'
export default {
  name: "my",
  data(){
      return{
          avatar:"",
          name:"",
          referrerUrl:"",
          type: Number(this.$route.query.type)
      }
  },
  methods: {
    onClick () {
      console.log('click')
    }
  },
  components: {
    tabbar
  }, 
  mounted:function(){
    

    const token = $.cookie('token');
    const userId = $.cookie('userId') || '';
    var contentjson = {"userId":userId};
    let reqArguments = {
       openid:info.appid,
       content:JSON.stringify(contentjson),
       method:'dusun.crm.api.getuserinfo',
       token:token,
       version:info.version,
     }
     const sign = this.$md5(JSON.stringify(reqArguments).replace(/\\/g,''))
     const _this = this;
     
      $.ajax({
        url:"http://192.168.124.6:8866/gateway", // 
        type:"post",
        data:{
          openid:info.appid,
          content:JSON.stringify(contentjson),
          method:'dusun.crm.api.getuserinfo',
          sign:sign,
          token:token,
          version:info.version,
        },
        success:function(data) {
          if(data.code == "200"){
              _this.avatar = data.data.avatar
              _this.name = data.data.name; 
              _this.referrerUrl = data.data.referrerUrl;//推荐码
              $.cookie("referrerUrl", data.data.referrerUrl);
          }else if(data.code == "3003") {
            TopTips({
              message: '账号不存在',
              duration: 5000
            });
            _this.$router.push({
                path: '/'
            })
          }else if(data.code == "1000" || data.code == "1001" || data.code == "1002" || data.code == "1003"){

            Dialog.confirm({
              title: "请求失败",
              message: '请重新登录',
              skin:'ios',
              showCancelButton: false
            }).then(() => {
              // this.$root.message('confirmed')
              _this.$router.push({
                  path: '/'
              })
            })
            
          }
          
        },
        error:function(error){
          console.log("error")
          _this.$router.push({
                path: '/'
            })
        }
      })
     
  }
 
  
};
</script>


<style lang="scss">
@import '../base/reset.scss';
@import "../base/common.scss";

.myhome {
    text-align:left;
    .head {
        .avatar {
            width:pxTorem(112);
            height:pxTorem(112);
            margin-left:pxTorem(40);
            margin: pxTorem(40) 0 pxTorem(40) pxTorem(40);
            border-radius:10px;
        }
        .weui-cells {
            height:100%;
            margin-top:0;
            &:before {
                border-top:none
            }
        }
        .name {
            font-size:pxTorem(24);
            display: inline-block;
            margin-left: pxTorem(10)
        }
    }
    .weui-cell{
        
        &:before {
            left:0
        }
        .weui-cell__bd {
            font-size:pxTorem(28)
        }
    }
}


</style>